package com.zy.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
 * @Author GongXl
 * @Description 
 * @Date 012 15:29
 * @Param 
 * @return 
**/
public class DispactherServlet extends HttpServlet {
    @Override
    public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String method = req.getParameter("method");
        if(null != method){
            Method callMethod = null;
            try {
                callMethod = this.getClass().getMethod(method, HttpServletRequest.class, HttpServletResponse.class);
                try {
                    if(null != callMethod) {
                        callMethod.invoke(this,req, res);
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
    }
}
